package com.tjetc.service.Impl;

import com.tjetc.dao.OrderDetailMapper;
import com.tjetc.entity.OrderDetail;
import com.tjetc.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class OrderDetailServiceImpl implements OrderDetailService {

    @Autowired
    OrderDetailMapper orderDetailMapper;

    /***
     * 订单id查询订单详情
     * @param orderId
     * @return
     */
    @Override
    public List<OrderDetail> selectByOrderId(int orderId) {
        return orderDetailMapper.selectByOrderId(orderId);
    }

    /***
     * 添加订单详情
     * @param orderDetail
     * @return
     */
    @Override
    public int addOrderDetail(OrderDetail orderDetail) {
        return orderDetailMapper.addOrderDetail(orderDetail);
    }

    @Override
    public BigDecimal computed(List<OrderDetail> list){
        BigDecimal amount=new BigDecimal(0);
        for(int i=0;i<list.size();i++){
            BigDecimal dishAmount=list.get(i).getAmount();
            amount=amount.add(dishAmount);
        }
        return amount;
    }


}
